package com.spj.controller;

import com.spj.entity.JOne;
import com.spj.entity.JUser;
import com.spj.entity.JsonMessage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author :spj
 * @Date:2022/3/31
 * @description:
 */
@Controller
@RequestMapping("/json")
public class JacksonTest {
    @RequestMapping("/demo1")
    public ModelAndView demo1(@RequestBody JUser user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name",user);
        modelAndView.setViewName("/WEB-INF/jsp/success.jsp");
        return modelAndView;
    }
    @RequestMapping("/demo2")
    public String demo2(Model model,@RequestBody String str){
        model.addAttribute("name",str);
        return "success";
    }
    @RequestMapping("/demo3")
    public String demo3(Model model,@RequestBody String str){
        model.addAttribute("name",str);
        return "redirect:/json/demo5?str=spj";
    }
    @RequestMapping("/demo4")
    public String demo4(Model model,@RequestBody String str){
        model.addAttribute("name",str);
        return "forward:/json/demo5?str=spj";
    }
    @RequestMapping("/demo5")
    public String demo5(Model model,String str){
        model.addAttribute("name",str);
        return "success";
    }
    @ResponseBody
    @RequestMapping("/demo6")
    public JsonMessage demo6(@RequestBody JOne jOne){
        if (jOne==null){
            return JsonMessage.FAILED;
        }else {
            return new JsonMessage(200,"成功",jOne);
        }
    }
}
